package com.smh.a04SetDemo1;

import java.util.TreeSet;

public class TreeSetDemo3 {
    public static void main(String[] args) {

        Student student = new Student("asd",12,"nan");
        Student student2 = new Student("qwe",13,"nan");
        Student student3 = new Student("zxc",14,"nv");
        Student student4= new Student("fg2h",11,"nan");


        //为了不去修改源码,我们自己添加比较规则
        TreeSet<Student> ts = new TreeSet<>((o1, o2) -> {
                int i = o1.getName().length() - o2.getName().length();
                i = i==0?o1.compareTo(o2):i;
                return i;
        });
        ts.add(student);
        ts.add(student2);
        ts.add(student3);
        ts.add(student4);
        System.out.println(ts);
    }
}
